<template>
    <div class="addOrEdit">
        <el-dialog
            :before-close="handClose"
            center
            width="30%"
            title="新增推送"
            :visible.sync="off"
            append-to-body>
            <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" size="mini" class="demo-ruleForm">
                <el-form-item label="标题" prop="title">
                    <el-input v-model.trim="ruleForm.title"></el-input>
                </el-form-item>
                 <el-form-item label="平台名" prop="platform">
                    <el-select v-model="ruleForm.platform" :style="{width: '100%'}">
                        <el-option v-for="(item, index) in [{label: '安卓平台', value: '安卓'}]" :key="index" :label="item.label" :value="item.value"></el-option>
                    </el-select>
                </el-form-item>
                 <el-form-item label="目标人群名称" prop="deliveryValue">
                    <el-select :style="{width: '100%'}" v-model="ruleForm.deliveryValue">
                        <el-option v-for="(item, index) in [{label: '广播(所有人)', value: '广播'}]" :key="index" :label="item.label" :value="item.value"></el-option>
                    </el-select>
                </el-form-item>
                 <el-form-item label="离线消息保留时长名" prop="receiverValue">
                     <el-select :style="{width: '100%'}" v-model="ruleForm.receiverValue">
                        <el-option v-for="(item, index) in retainTime" :key="index" :label="item.label" :value="item.value"></el-option>
                    </el-select>
                </el-form-item>
                 <el-form-item label="定时" prop="sendTime">
                    <el-input v-model.trim="ruleForm.sendTime"></el-input>
                </el-form-item>
                <el-form-item label="指定路径" prop="intentUrl">
                    <el-input v-model.trim="ruleForm.intentUrl"></el-input>
                </el-form-item>
                <el-form-item label="样式ID" prop="builderId">
                    <el-input v-model.trim="ruleForm.builderId"></el-input>
                </el-form-item>
                <el-form-item label="内容" prop="content">
                    <el-input v-model.trim="ruleForm.content"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="create">立即创建</el-button>
            </div>
        </el-dialog>
    </div>
   
</template>

<script>
    import { addPush } from "@/api/supermarket/push.js"
    export default {
        name: "addPush",
        props: {
            off: {
                type: Boolean
            },
            rowData: {
                type: Object
            },
        },
        watch: {
            off(val){
                if(val){
                   
                    
                }
            }
        },
        data(){
            return {
                retainTime: [
                    {label: "30分钟", value: "30分钟"},
                    {label: "一天", value: "1天"},
                    {label: "二天", value: "2天"},
                ],
                rules: {
                     title: [{ required: true, message: "标题不能为空", trigger: "blur" }],
                     platform: [{ required: true, message: "平台不能为空", trigger: "change" }],
                     deliveryValue: [{ required: true, message: "目标人群不能为空", trigger: "change" }],
                     sendTime: [{ required: true, message: "定时不能为空", trigger: "blur" }],
                     content: [{ required: true, message: "内容不能为空", trigger: "blur" }]
                },
                ruleForm: {
                    title: "",
                    platform: "",
                    deliveryValue: "",
                    receiverValue: "",
                    sendTime: "",
                    intentUrl:"",
                    builderId: "",
                    content: ""
                }
            }
        },
        methods: {
            handClose(){
                this.$emit("update:off", false);
            },
            create(){
                this.$refs.ruleForm.validate((valid) => {
                    if(!valid){
                        return;
                    }else{
                        addPush(this.ruleForm).then(
                            res => {
                                console.log("res新增推送成", res);
                                this.$message({
                                    type: "success",
                                    message: "新增推送成功"
                                });
                                this.$emit("update:off", false);
                                this.$parent.getList();
                                this.$refs.ruleForm.resetFields();
                            },
                            err => {}
                        );
                        
                    }
                });
            }
        }
    }
</script>

<style scoped lang="less">

</style>